package com.yohann.boot.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yohann.boot.entity.LogRecord;
import com.yohann.boot.service.LogRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.scheduling.annotation.Async;

/**
 * @author Yeung Wah
 * @since 2022/1/5
 */
@Slf4j
public class SaveLogServiceImpl extends LogRecordService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Async
    @Override
    public void record(LogRecord logRecord) {
        logRecord.setThrowable(JSONObject.parseObject(JSON.toJSONString(logRecord.getThrowable())));
        mongoTemplate.save(logRecord);
    }
}